package home.contaduria.dao.jpa;

import home.contaduria.dao.IncomeTypeDao;
import home.contaduria.domain.Client;
import home.contaduria.domain.IncomeType;

import java.util.Collection;

import org.springframework.dao.support.DataAccessUtils;
import org.springframework.stereotype.Repository;

@Repository("incomeTypeDaoJpa")
public class IncomeTypeDaoJpaImpl extends GenericDaoJpaImpl<IncomeType, Long> implements IncomeTypeDao {

    @Override
    public IncomeType findIncomeType(String name, Client client) {
        return DataAccessUtils.singleResult(getEntityManager().createNamedQuery("IncomeType.findIncomeType", IncomeType.class)
                .setParameter("client", client).setParameter("name", name).getResultList());
    }

    @Override
    public Collection<IncomeType> loadClientIncomeTypes(Client client) {
        return getEntityManager().createNamedQuery("IncomeType.loadClientIncomeType", IncomeType.class).setParameter("client", client)
                .getResultList();
    }

}
